home *** CD-ROM | disk | FTP | other *** search
- #include <stdio.h>
- #include <hamdefs.h>
- #include <ctype.h>
-
- char *index(),*rindex(),*calloc();
- char line[132];
- char **lines;
- int linecount,width,height;
- FILE *ptr, *fopen();
-
- type(filename,top,left,bottom,right)
- char *filename;
- int top,left,bottom,right;
- {
- /* this routine displays a file in the lower window of the
- screen, and allows the user to use the cursor keys to
- view more and more of the file. standard text files
- are used, which can also be printed and used by other
- DOS functions
- */
- int cur_top,i,j;
-
- lines=calloc(100,sizeof(char *));
- csrpush();
- width=right-left-1;
- height=bottom-top-1;
- linecount=0;
-
- clrblk(top,left,bottom,right);
- scrbox(top,left,bottom,right,3,NORMAL|HILITE);
- atputsha(top,left+(width/2)-6,"Press \030 or \031");
- atputsha(bottom,left+(width/2)-6,"Esc when done");
-
- ptr=fopen(filename,"r");
- if(ptr==NULL) {
- clrblk(top,left,bottom,right);
- csrpop();
- free(lines);
- return -1;
- }
-
- fillarray();
-
- cursor(FALSE);
- for(i=0;i<linecount && i<height; i++)
- atputsha(top+1+i,left+1,lines[i]);
-
- cur_top=0;
-
- for(;;) {
- switch(j=inkeyi()) {
- case HOME: cur_top=0;
- clrblk(top+1,left+1,bottom-1,right-1);
- for(i=0;i<linecount && i<height; i++)
- atputsha(top+1+i,left+1,lines[i]);
- break;
-
- case END: cur_top=linecount-height;
- clrblk(top+1,left+1,bottom-1,right-1);
- for(i=0;i<linecount && i<height; i++)
- atputsha(top+1+i,left+1,lines[i+cur_top]);
- break;
-
- case PAGEUP:
- if(cur_top==0)
- break;
- cur_top-=height;
- if(cur_top<0)
- cur_top=0;
- clrblk(top+1,left+1,bottom-1,right-1);
- for(i=0;i<linecount && i<height; i++)
- atputsha(top+1+i,left+1,lines[i+cur_top]);
- break;
-
- case PAGEDN:
- if(cur_top==linecount-height)
- break;
- cur_top+=height;
- if(cur_top>(linecount-height))
- cur_top=linecount-height;
- clrblk(top+1,left+1,bottom-1,right-1);
- for(i=0;i<linecount && i<height; i++)
- atputsha(top+1+i,left+1,lines[i+cur_top]);
- break;
-
- case DOWN: if(cur_top+height < linecount) {
- ++cur_top;
- scroll(1,top+1,left+1,bottom-1,right-1);
- atputsha(bottom-1,left+1,lines[cur_top+height-1]);
- }
- break;
- case UP: if(cur_top>0) {
- --cur_top;
- scroll(-1,top+1,left+1,bottom-1,right-1);
- atputsha(top+1,left+1,lines[cur_top]);
- }
- break;
- case ESC: clrblk(top,left,bottom,right);
- cursor(TRUE);
- csrpop();
- for(i=0;i<linecount;i++)
- free(lines[i]);
- free(lines);
- return 0;
- break;
- default: break;
- }
- }
- }
-
- cursor(select)
- int select;
- {
- if(select)
- v_scsrtp(12,13);
- else
- v_scsrtp(15,15);
- }
-
- fillarray()
- {
- int length,i,j;
- char *leftcp,*rightcp;
-
- lines[linecount]=calloc(width+1,sizeof(char));
- while(!feof(ptr)) {
- if(!fgets(line,sizeof(line),ptr))
- break;
- leftcp=rightcp=&line[0];
- *index(line,'\n')='\0';
- if(!strlen(line)) {
- linecount+=2;
- lines[linecount-1]=calloc(1,1);
- lines[linecount]=calloc(width+1,sizeof(char));
- continue;
- }
-
- /* both ptrs at first letter */
-
- while(*rightcp) {
- while(!(isspace(*rightcp)) && (*rightcp!='\0'))
- ++rightcp;
- length=rightcp-leftcp;
- if(strlen(lines[linecount])+length < width) {
- strncat(lines[linecount],leftcp,length);
- strcat(lines[linecount]," ");
- } else {
- lines[++linecount]=calloc(width+1,sizeof(char));
- strncat(lines[linecount],leftcp,length);
- strcat(lines[linecount]," ");
- }
- leftcp=rightcp;
- while(isspace(*leftcp) && *leftcp!='\0')
- ++leftcp,++rightcp;
- }
- }
- ++linecount;
- }
-
- center(row,string)
- int row;
- char *string;
- {
- atputsha(row,40-(strlen(string)/2),string);
- }
-